/*
 * @Author: suxunying
 * @desc: user module
 * @Date: 2021-07-20 17:40:05
 * @LastEditors: suxunying
 * @LastEditTime: 2021-07-26 11:07:40
 * @FilePath: \bmp-poc\plat\src\store\modules\locale.ts
 */
/* eslint no-shadow: ["error",{ "allow": ["state"] }] */
import shared from '@/shared';

interface State {
    locale: string,
}

const state: State = {
    locale: ''
};

const getters = {
    locale: (state: State) => state.locale,
};

const actions = {
    setLocale({ commit }: any, locale: string): Promise<any> {
        return new Promise((resolve, reject) => {
            commit('SET_LOCALE', locale);
            shared.dispatch('locale/setLocale', locale);
            resolve(locale);
        });
    },
};

const mutations = {
    SET_LOCALE: (state: State, locale: string) => {
        state.locale = locale;
    },
};

export default {
    namespace: true,
    state,
    getters,
    actions,
    mutations,
};
